import { API } from "../utils";
export const getCurrentCity = () => {
  // 判断localStorage 中是否有定位城市
  const localCity = JSON.parse(localStorage.getItem("hkzf_city"));
  if (!localCity) {
    // 没有,就获取定位城市
    return new Promise((resolve, reject) => {
      const myCity = new window.BMapGL.LocalCity();
      myCity.get(async (res) => {
        try {
          const result = await API.get("/area/info", {
            params: { name: res.name },
          });
          // 存储到本地存储中
          localStorage.setItem("hkzf_city", JSON.stringify(result.data.body));
          // 返回该城市数据
          resolve(result.data.body);
        } catch (e) {
          reject(e);
        }
      });
    });
  }
  // 因为上面if return的是一个promise对象,所以下面也return Promise对象
  // 因为此处Promise不会失败,所以只返回resolve就行
  return Promise.resolve(localCity);
};

export { API } from "./api";
export { BASE_URL } from "./url";
export { getCity, setCity } from "./city";
// 导出 auth 模块中所有内容
export * from "./auth";
